/*
 * @FilePath: /tads/server/initialize/db_postgres.go
 * @Author: wnina0x0
 * @Date: 2025-04-03 17:33:40
 * @Description:
 *
 * 版权信息 : 2025 by wnina0x0, All Rights Reserved.
 */
package initialize

import (
	"log"
	"tads/server/global"

	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

func GormPostgres() *gorm.DB {
	if *global.TADS_DBNAME == "" {
		log.Printf("GormPostgres err\n")

		return nil
	}
	log.Println(global.TADS_DSN)
	postgresConfig := postgres.Config{
		DSN:                  global.TADS_DSN, // DSN data source name
		PreferSimpleProtocol: false,
	}
	if db, err := gorm.Open(postgres.New(postgresConfig)); err != nil {
		log.Printf("GormPostgres err\n")
		return nil
	} else {
		db.InstanceSet("gorm:table_options", "TABLESPACE pg_default")
		log.Printf("GormPostgres success\n")
		return db
	}
}
